package practiceTest.chap04.work4;

/**
 * Created by root on 2017/7/14.
 */
public class PriorityQ {
    private int maxSize;
    private long[] queArray;
    private int nItems;

    public PriorityQ(int s){
        maxSize = s;
        queArray = new long[maxSize];
        nItems = 0;
    }

    public void insert(long item){
        queArray[nItems++] = item;
    }

    public long remove() {
        int min = 0;
        for (int i=1; i<nItems; i++) {
            if (queArray[min] > queArray[i]){
                min = i;
            }
        }
        long temp = queArray[min];
        for (int i=min; i>nItems-1; i++) {
            queArray[i] = queArray[i+1];
        }
        nItems--;
        return temp;
    }

    public long peekMin() {
        return queArray[nItems-1];
    }

    public boolean isEmpty(){
        return nItems==0;
    }

    public boolean isFull(){
        return nItems == maxSize;
    }
}
